<template>
  <div class="dp-index">
    <nav-header></nav-header>
    <div class="msg-box">
      <p>{{msgData}}算法</p>
      <span>基于深度学习的算法</span>
    </div>
    <div class="sd-box">
      <div class="ellipse-carousel-container">
        <!-- 轮播容器 -->
        <div class="ellipse-carousel">
          <!-- 轮播项 -->
          <div
            v-for="(item, index) in items"
            :key="index"
            class="carousel-item"
            :style="getItemStyle(index)"
          >
            <img :src="item" alt="">
          </div>
        </div>
        <!-- 控制按钮 -->
        <!-- <button class="carousel-button prev" @click="prev">Prev</button>
        <button class="carousel-button next" @click="next">Next</button> -->
      </div>
    </div>
  </div>
</template>
<script>
import navHeader from "./components/navHeader.vue";
export default {
  name: "analysis",
  components: {
    navHeader,
  },
  data() {
    return {
      items: [require('@/assets/images/sf1.png'), require('@/assets/images/sf2.png'), require('@/assets/images/sf3.png'), require('@/assets/images/sf4.png'), require('@/assets/images/sf5.png')], // 轮播内容
      currentIndex: 0, // 当前显示的轮播项索引
      totalItems: 5, // 轮播项总数
      radiusX: 650, // 椭圆 X 轴半径
      radiusY: 120, // 椭圆 Y 轴半径
      angleStep: (2 * Math.PI) / 5, // 每个项之间的角度步长
      timeout: null, // 定时器
      msgData:'力学模型',
      titles:['力学模型','人工智能模型','地理模型','风力模型','气候模型'],
    };
  },
  computed: {
    // 计算每个项的角度
    itemAngles() {
      return Array.from(
        { length: this.totalItems },
        (_, i) => i * this.angleStep
      );
    },
  },
  mounted() {
    this.timeout = setInterval(() => {
      this.next();
    }, 10000);
  },
  beforeDestroy() {
    clearInterval(this.timeout);
  },
  methods: {
    // 计算每个轮播项的样式
    getItemStyle(index) {
      const angle = this.itemAngles[index] + this.currentIndex * this.angleStep;
      const x = this.radiusX * Math.cos(angle)+300; // X 坐标
      const y = this.radiusY * Math.sin(angle); // Y 坐标
      return {
        transform: `translate(${x}px, ${y}px)`,
        // opacity: 1 - Math.abs(index - this.currentIndex) * 0.1, // 透明度渐变
      };
    },
    // 切换到上一个项
    prev() {
      this.currentIndex = (this.currentIndex - 1 + this.totalItems) % this.totalItems;
    },
    // 切换到下一个项
    next() {
      this.currentIndex = (this.currentIndex + 1) % this.totalItems;
      this.msgData = this.titles[this.currentIndex]
    },
  },
};
</script>
<style lang="scss" scoped>
.dp-index {
  width: 100%;
  height: 100%;
  background: url("../../assets/images/sf.png") no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}
.msg-box{
  width: 30%;
  position: absolute;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: rgba(2, 26, 65, 0.5);
  padding: 20px;
  box-sizing: border-box;
  p{
    font-size: 30px;
    color: #fff;
    font-family: 'youshe';
    margin: 10px 0;
  }
  span{
    font-size: 14px;
    color: #fff;
  }
}
.sd-box {
  width: 100%;
  position: absolute;
  left: 0;
  bottom: 120px;
}
.ellipse-carousel-container {
  position: relative;
  width: 1000px;
  height: 300px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 轮播容器 */
.ellipse-carousel {
  position: relative;
  width: 100%;
  height: 100%;
}

/* 轮播项 */
.carousel-item {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
  img{
    width: 200px;
  }
}
/* 控制按钮 */
.carousel-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  padding: 10px;
  cursor: pointer;
}

.carousel-button.prev {
  left: 10px;
}

.carousel-button.next {
  right: 10px;
}
</style>
